using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameObjectPool : PoolBase
{
    public override Object Spwan(string name)
    {
        Object obj = base.Spwan(name);

        if(obj == null)
            return null;

        GameObject gameObject = obj as GameObject;
        gameObject.SetActive(true);

        return gameObject;
    }

    public override void UnSpwan(string name, Object obj)
    {
        GameObject gameObject = obj as GameObject;
        gameObject.SetActive(false);
        gameObject.transform.SetParent(this.transform, false);
        base.UnSpwan(name, obj); 
    }

    public override void Release()
    {
        base.Release();

        foreach (var item in poolObjects)
        {
            if(System.DateTime.Now.Ticks - item.LastUseTime.Ticks >= releaseTime * 10000000)
            {
                Debug.Log("GameObject in pool release time :" + System.DateTime.Now.ToString());
                Destroy(item.Object);
                Manager.Resources.MinusBundleCount(item.Name);
                poolObjects.Remove(item);
                Release();
                return;
            }
        }
    }
}
